//
//  GiftColCell.swift
//  WalkNovel
//
//  Created by Kevin on 2023/9/18.
//

import UIKit

class GiftColCell: UICollectionViewCell {
    
    lazy var giftImage: UIImageView = {
        let image = UIImageView()
        return image
    }()
    
    lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 12)
        label.textColor = .black
        label.textAlignment = .center
        return label
    }()
    
    lazy var goldBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setImage(UIImage(named: "book_coin"), for: .normal)
        btn.setTitleColor(.white, for: .normal)
        btn.titleLabel?.font = .wn_font(name: .bold, size: 12)
        return btn
    }()
    
    var model: GiftModel? {
        didSet {
            if let m = model {
                giftImage.wn_setupImg(m.cover, placeHolder: "gift_send")
                nameLabel.text = m.name
                goldBtn.setTitle("\(m.gold)", for: .normal)
                let color: UIColor = m.isSelected ? .init(named: "red_FE95B4")! : .black
                nameLabel.textColor = color
                goldBtn.setTitleColor(color, for: .normal)
                wn_cornerWithBorder(8, m.isSelected ? 1.5 : 0, color)
            }
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(goldBtn)
        addSubview(nameLabel)
        addSubview(giftImage)
        goldBtn.snp.makeConstraints { (make) in
            make.bottom.equalTo(-12)
            make.left.equalTo(10)
            make.right.equalTo(-10)
            make.height.equalTo(12)
        }
        nameLabel.snp.makeConstraints { (make) in
            make.bottom.equalTo(goldBtn.snp.top).offset(-12)
            make.left.equalTo(10)
            make.right.equalTo(-10)
            make.height.equalTo(14)
        }
        giftImage.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(12)
            make.bottom.equalTo(nameLabel.snp.top).offset(-6)
            make.width.equalTo(giftImage.snp.height)
        }
        goldBtn.layoutButton(style: .left, imageTitleSpace: 2)
    }
    
    func playGiftAnimationView() {
        stopGiftAnimationView()
        giftImage.isHidden = true
    }
    
    func stopGiftAnimationView() {
        giftImage.isHidden = false
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
